package com.dragon.modules.yuegou.model.message;

import com.dragon.modules.yuegou.entity.message.TriggerEntity;
import com.dragon.modules.yuegou.enums.Platform;
import com.dragon.modules.yuegou.enums.message.MessageChannel;
import com.dragon.modules.yuegou.enums.message.TriggerStatus;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 消息触发器（事件触发推送模板消息）模型类
 * 
 * @author pbuilder generated
 * @date 2019-04-18 11:24:17
 * @company sgy
 * @version 2.0
 * @see Length 长度限制
 * @see NotNull 对象非空
 * @see NotEmpty 字符串、集合、表、数组非空
 */
public class Trigger extends TriggerEntity {

	@ApiModelProperty("模板名称")
	private String templateName;

	@ApiModelProperty("事件名称")
	private String eventName;

	public String getTemplateName() {
		return templateName;
	}

	public void setTemplateName(String templateName) {
		this.templateName = templateName;
	}

	public String getEventName() {
		return eventName;
	}

	public void setEventName(String eventName) {
		this.eventName = eventName;
	}

	/**
	 * 构造一个空消息触发器（事件触发推送模板消息）模型对象
	 */
	public Trigger() {
		super();
	}

	/**
	 * 依据实体对象的信息构造一个消息触发器（事件触发推送模板消息）模型对象
	 * 
	 * @param entity
	 *            实体对象
	 */
	public Trigger(TriggerEntity entity) {
		super(entity);
	}

	/**
	 * 依据其它对象的信息构造一个消息触发器（事件触发推送模板消息）模型对象
	 * 
	 * @param other
	 *            其它对象
	 */
	public Trigger(Trigger other) {
		super(other);
	}

	@Override
	public String getId() {
		return id;
	}

	/**
	 * 设置
	 * 
	 * @param id
	 * @return 当前对象
	 */
	public Trigger id(String id) {
		this.id = id;
		return this;
	}

	@Override
	public Platform getPlatform() {
		return platform;
	}

	/**
	 * 设置[全局枚举]平台：0-悦商圈-YSQ_APP、1-悦购-YSQ_XCX、2-悦商惠小程序-YSQ_MERCHANT_XCX、3-集团版-YSQ_GROUP、4-大运营平台-YSQ_PLATFORM
	 * 
	 * @param platform
	 *            [全局枚举]平台：0-悦商圈-YSQ_APP、1-悦购-YSQ_XCX、2-悦商惠小程序-YSQ_MERCHANT_XCX、3-集团版-YSQ_GROUP、4-大运营平台-YSQ_PLATFORM
	 * @return 当前对象
	 */
	public Trigger platform(Platform platform) {
		this.platform = platform;
		return this;
	}

	@Override
	public String getTitle() {
		return title;
	}

	/**
	 * 设置触发器标题
	 * 
	 * @param title
	 *            触发器标题
	 * @return 当前对象
	 */
	public Trigger title(String title) {
		this.title = title;
		return this;
	}

	@Override
	public String getTemplateId() {
		return templateId;
	}

	/**
	 * 设置消息模板ID
	 * 
	 * @param templateId
	 *            消息模板ID
	 * @return 当前对象
	 */
	public Trigger templateId(String templateId) {
		this.templateId = templateId;
		return this;
	}

	@Override
	public String getEventType() {
		return eventType;
	}

	/**
	 * 设置事件类型
	 * 
	 * @param eventType
	 *            事件类型
	 * @return 当前对象
	 */
	public Trigger eventType(String eventType) {
		this.eventType = eventType;
		return this;
	}

	@Override
	public String getArgNames() {
		return argNames;
	}

	/**
	 * 设置参数名称列表，以|隔开
	 * 
	 * @param argNames
	 *            参数名称列表，以|隔开
	 * @return 当前对象
	 */
	public Trigger argNames(String argNames) {
		this.argNames = argNames;
		return this;
	}

	@Override
	public String getTitleArgNames() {
		return titleArgNames;
	}

	/**
	 * 设置标题参数名称列表，以|隔开
	 * 
	 * @param titleArgNames
	 *            标题参数名称列表，以|隔开
	 * @return 当前对象
	 */
	public Trigger titleArgNames(String titleArgNames) {
		this.titleArgNames = titleArgNames;
		return this;
	}

	@Override
	public String getUrlArgNames() {
		return urlArgNames;
	}

	/**
	 * 设置跳转地址参数名称列表，以|隔开
	 * 
	 * @param urlArgNames
	 *            跳转地址参数名称列表，以|隔开
	 * @return 当前对象
	 */
	public Trigger urlArgNames(String urlArgNames) {
		this.urlArgNames = urlArgNames;
		return this;
	}

	@Override
	public Boolean getSupportSystem() {
		return supportSystem;
	}

	/**
	 * 设置是否支持系统消息
	 * 
	 * @param supportSystem
	 *            是否支持系统消息
	 * @return 当前对象
	 */
	public Trigger supportSystem(Boolean supportSystem) {
		this.supportSystem = supportSystem;
		return this;
	}

	@Override
	public Boolean getSupportSms() {
		return supportSms;
	}

	/**
	 * 设置是否支持短信推送
	 * 
	 * @param supportSms
	 *            是否支持短信推送
	 * @return 当前对象
	 */
	public Trigger supportSms(Boolean supportSms) {
		this.supportSms = supportSms;
		return this;
	}

	@Override
	public Boolean getSupportEmail() {
		return supportEmail;
	}

	/**
	 * 设置是否支持邮件推送
	 * 
	 * @param supportEmail
	 *            是否支持邮件推送
	 * @return 当前对象
	 */
	public Trigger supportEmail(Boolean supportEmail) {
		this.supportEmail = supportEmail;
		return this;
	}

	@Override
	public Boolean getSupportJpush() {
		return supportJpush;
	}

	/**
	 * 设置是否支持极光推送
	 * 
	 * @param supportJpush
	 *            是否支持极光推送
	 * @return 当前对象
	 */
	public Trigger supportJpush(Boolean supportJpush) {
		this.supportJpush = supportJpush;
		return this;
	}

	@Override
	public Boolean getSupportWechat() {
		return supportWechat;
	}

	/**
	 * 设置支持微信公众号推送
	 * 
	 * @param supportWechat
	 *            支持微信公众号推送
	 * @return 当前对象
	 */
	public Trigger supportWechat(Boolean supportWechat) {
		this.supportWechat = supportWechat;
		return this;
	}

	@Override
	public TriggerStatus getStatus() {
		return status;
	}

	/**
	 * 设置[枚举]状态：0-暂存-TEMP、1-已启用-ENABLED、2-禁用-DISABLED
	 * 
	 * @param status
	 *            [枚举]状态：0-暂存-TEMP、1-已启用-ENABLED、2-禁用-DISABLED
	 * @return 当前对象
	 */
	public Trigger status(TriggerStatus status) {
		this.status = status;
		return this;
	}

	@Override
	public String getCreatedBy() {
		return createdBy;
	}

	/**
	 * 设置创建人ID
	 * 
	 * @param createdBy
	 *            创建人ID
	 * @return 当前对象
	 */
	public Trigger createdBy(String createdBy) {
		this.createdBy = createdBy;
		return this;
	}

	@Override
	public LocalDateTime getCreatedTime() {
		return createdTime;
	}

	/**
	 * 设置创建时间
	 * 
	 * @param createdTime
	 *            创建时间
	 * @return 当前对象
	 */
	public Trigger createdTime(LocalDateTime createdTime) {
		this.createdTime = createdTime;
		return this;
	}

	@Override
	public String getModifiedBy() {
		return modifiedBy;
	}

	/**
	 * 设置更新人ID
	 * 
	 * @param modifiedBy
	 *            更新人ID
	 * @return 当前对象
	 */
	public Trigger modifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
		return this;
	}

	@Override
	public LocalDateTime getModifiedTime() {
		return modifiedTime;
	}

	/**
	 * 设置更新时间
	 * 
	 * @param modifiedTime
	 *            更新时间
	 * @return 当前对象
	 */
	public Trigger modifiedTime(LocalDateTime modifiedTime) {
		this.modifiedTime = modifiedTime;
		return this;
	}

	@Override
	public Boolean getDel() {
		return del;
	}

	/**
	 * 设置是否删除
	 * 
	 * @param del
	 *            是否删除
	 * @return 当前对象
	 */
	public Trigger del(Boolean del) {
		this.del = del;
		return this;
	}

	@Override
	public String getDelBy() {
		return delBy;
	}

	/**
	 * 设置删除人ID
	 * 
	 * @param delBy
	 *            删除人ID
	 * @return 当前对象
	 */
	public Trigger delBy(String delBy) {
		this.delBy = delBy;
		return this;
	}

	@Override
	public LocalDateTime getDelTime() {
		return delTime;
	}

	/**
	 * 设置删除时间
	 * 
	 * @param delTime
	 *            删除时间
	 * @return 当前对象
	 */
	public Trigger delTime(LocalDateTime delTime) {
		this.delTime = delTime;
		return this;
	}

	@JsonIgnore
	public List<String> getArgNameList() {
		if (StringUtils.isEmpty(argNames)) {
			return Collections.emptyList();
		}
		return Arrays.asList(argNames.split("\\|"));
	}

	@JsonIgnore
	public List<String> getTitleArgNameList() {
		if (StringUtils.isEmpty(titleArgNames)) {
			return Collections.emptyList();
		}
		return Arrays.asList(titleArgNames.split("\\|"));
	}

	@JsonIgnore
	public List<String> getUrlArgNameList() {
		if (StringUtils.isEmpty(urlArgNames)) {
			return Collections.emptyList();
		}
		return Arrays.asList(urlArgNames.split("\\|"));
	}

	@JsonIgnore
	public List<MessageChannel> getSupportedChannels() {
		List<MessageChannel> channels = new ArrayList<>();
		if (this.supportSystem) {
			channels.add(MessageChannel.SYSTEM);
		}
		if (this.supportSms) {
			channels.add(MessageChannel.SMS);
		}
		if (this.supportEmail) {
			channels.add(MessageChannel.EMAIL);
		}
		if (this.supportJpush) {
			channels.add(MessageChannel.JPUSH);
		}
		if (this.supportWechat) {
			channels.add(MessageChannel.WECHAT);
		}
		return channels;
	}
}
